/*
 *  Copyright (C) 2010 Glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.common.defaults;

import java.util.ArrayList;
import java.util.List;
import org.balisunrise.common.Criterion;
import org.balisunrise.common.Query;
import org.balisunrise.common.abstracts.AbstractBasic;

/**
 *
 * @author Glauco
 */
public class DefaultBaliQuery extends AbstractBasic implements Query{

    private Class entityClass;
    private int firstResult;
    private int maxResults;
    private List<String> orders;
    private List<Criterion> criterions;

    public DefaultBaliQuery(Class entityClass) {
        this.entityClass = entityClass;
        clearOrder();
        clearCriterion();
    }

    @Override
    public Class getEntityClass() {
        return entityClass;
    }

    @Override
    public int getFirstResult() {
        return firstResult;
    }

    @Override
    public void setFirstResult(int firstResult) {
        this.firstResult = firstResult;
    }

    @Override
    public int getMaxResults() {
        return maxResults;
    }

    @Override
    public void setMaxResults(int maxResults) {
        this.maxResults = maxResults;
    }

    @Override
    public String[] getOrders() {
        return orders.toArray(new String[]{});
    }

    @Override
    public void addOrder(String order) {
        if (order != null)
            orders.add(order);
    }

    @Override
    public Criterion[] getCriterions() {
        return criterions.toArray(new Criterion[]{});
    }

    @Override
    public void addCriterion(Criterion criterion) {
        if (criterion != null)
            criterions.add(criterion);
    }

    @Override
    public void clearOrder() {
        orders = new ArrayList<String>();
    }

    @Override
    public void clearCriterion() {
        criterions = new ArrayList<Criterion>();
    }

    @Override
    public String toString() {
        return "DefaultBaliQuery{"
                + "entityClass=" + entityClass +
                "   orders=" + orders +
                "   criterions=" + criterions + '}';
    }
}
